package com.leetcode.LC;

public class LC680 {
    public boolean validPalindrome(String s) {

        char[] chars = s.toCharArray();
        int a = 0;
        int b = s.length() - 1;
        int count = 0;

        while (a < b) {
            if (chars[a] == chars[b]) {
                a++;
                b--;
            } else if (chars[a + 1] == chars[b]&&((a+2)<(b-1)?chars[a + 2] == chars[b-1]:true)) {
                a = a + 2;
                b--;
                count++;
                if (count > 1) {
                    return false;
                }
            } else if (chars[a] == chars[b - 1]&&((a+1)<(b-2)?chars[a+1] == chars[b - 2]:true)) {
                a++;
                b = b - 2;
                count++;
                if (count > 1) {
                    return false;
                }
            } else {
                return false;
            }
        }
        return true;
    }

    public static void main(String[] args) {
        System.out.println(new LC680().validPalindrome(
                "aguokepatgbnvfqmgmlcupuufxoohdfpgjdmysgvhmvffcnqxjjxqncffvmhvgsymdjgpfdhooxfuupuculmgmqfvnbgtapekouga"));
    }
}
